<%--
  Created by IntelliJ IDEA.
  User: zhangyuan
  Date: 2020-03-20
  Time: 18:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>热门文章</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div style="padding: 8px;">
   <%-- <div style="text-align: right">
        <button type="button" class="layui-btn layui-btn-sm" name="thisforum">返回本讨论区</button>
        <button type="button" class="layui-btn layui-btn-sm" name="forum" >返回讨论区列表</button>
    </div>--%>
    <table id="demo" lay-filter="test"></table>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="transfer">转移</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    var boardId = $.GetRequest().boardId

    layui.use(['table','form'], function(){
        var table = layui.table;
        var form = layui.form;
        //第一个实例
        var tableIns= table.render({
            elem: '#demo'
            ,url: '/bbs/selHotPost' //数据接口
            ,page: false //热门文章查询的是前十位帖子所以不用分页
            ,cols: [[ //表头
                {type: 'numbers', title: '排行', }
                ,{field: 'type', title: '分类', }
                ,{field: 'authorName', title: '作者', }
                ,{field: 'trueName', title: '实名', }
                ,{field: 'subject', title: '标题', }
                ,{field: 'textNums', title: '字节', }
                ,{title: '回/阅', align:"center",templet:function (d){
                        return d.replyCont+"/"+d.readCont;
                    }
                }
                ,{field: 'submitTime', title: '发表时间', }
                ,{ title: '操作',align:'center', toolbar: '#barDemo',minWidth:200} //这里的toolbar值是模板元素的选择器
            ]]
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "data": res.obj //解析数据列表
                };
            }
        });
        //监听工具条
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            // console.log(data)

            if(layEvent === 'transfer'){ //转移
                Transfer(data);
            } else if(layEvent === 'edit'){ //编辑
                layer.open({
                    type: 2
                    ,title: ['编辑', 'font-size:18px;']
                    ,maxmin:true
                    ,area: ['90%', '90%']
                    ,content: '/bbs/allNotice?boardId='+boardId+'&commentId='+data.commentId
                    ,btn:['保存','关闭']
                    ,btnAlign: 'c'
                    ,yes: function(index, layero){
                        //按钮【按钮一】的回调
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.editOver();
                        layer.close(index)
                        window.location.reload()
                    }
                });
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确认要删除该条数据吗？', function(index){
                    $.post('/bbs/delCom',{commentIds:data.commentId},function(res){
                        layer.msg('删除成功！',{icon:1, time: 2000}, function(){
                            tableIns.reload()
                            layer.close(index)
                        });
                    });
                });
            }
        });

        //转移主题
        function Transfer(data){
            layer.open({
                type: 1
                ,area :['400px', '250px']
                ,title: '帖子转移'
                ,content: '<div style="margin-top: 20px;">' +
                    '<form class="layui-form" >' +
                    ' <div class="layui-inline">\n' +
                    '      <label class="layui-form-label">转移至：</label>\n' +
                    '      <div class="layui-input-inline">\n' +
                    '        <select name="modules" lay-verify="required" lay-search="">\n' +
                    '        </select>\n' +
                    '      </div>\n' +
                    '    </div>' +
                    '</form>' +
                    '</div>'
                ,btn: ['确定', '取消']
                ,success: function(layero, index){
                    //类型
                    $.get('/bbs/Transfer',{boardId:''},function(res){
                        if (res.flag){
                            var option='';
                            var obj=res.obj;
                            for (var i=0;i<obj.length;i++){
                                option+='<option value="'+obj[i].BOARD_ID+'">'+obj[i].BOARD_NAME+'</option>';
                            }
                            $('select[name="modules"]').append(option);
                            $('select[name="modules"]').val(data.boardId);
                            form.render('select');
                        }
                    });
                }
                ,yes: function(index, layero){
                    //按钮【按钮一】的回调
                    var boardId=$('select[name="modules"]').val();
                    $.post('/bbs/updateTransfer',{commentId:data.commentId,boardId:boardId},function(res){
                        if(res.flag){
                            layer.msg('转移成功!', {icon:1, time: 2000});
                            tableIns.reload();
                            layer.close(index);
                        }
                    });
                }
            });
        }
    });

    //返回本讨论区
    $("button[name='thisforum']").click(function(){
        window.location.href="/bbs/theme?boardId="+boardId;
    });
    //返回讨论区列表
    $("button[name='forum']").click(function(){
        window.location.href="/bbs/index";
    });
</script>
</body>
</html>
